package com.drawu.drawuspring.controller;

import com.drawu.drawuspring.domain.DTO.FocusBehaviorDto;
import com.drawu.drawuspring.domain.DTO.UserDTO;
import com.drawu.drawuspring.domain.DTO.UserLoginDTO;
import com.drawu.drawuspring.domain.Result;
import com.drawu.drawuspring.domain.VO.UserLoginVO;
import com.drawu.drawuspring.domain.VO.UserVO;
import com.drawu.drawuspring.domain.po.Users;
import com.drawu.drawuspring.service.IUsersService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/user")
@Slf4j
@RequiredArgsConstructor
@Tag(name = "用户相关接口")
public class UserController {

         private final  IUsersService usersService;

    // 登录
    @PostMapping("/login")
    @Operation(summary = "用户登录接口")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        log.info("用户登录接口");
        UserLoginVO loginVO = usersService.login(userLoginDTO);
        return Result.success(loginVO) ;
    }

    //保存用户信息
    @PostMapping("/save")
    @Operation(summary = "保存用户信息")
    public Result save(@RequestBody UserDTO userDTO) {
        return usersService.saveUserData(userDTO);
    }

    //头像上传
    @PostMapping("/uploadAvatar")
    @Operation(summary = "头像上传")
    public Result uploadAvatar(@RequestParam("file") MultipartFile mpFile, @RequestParam("userId") Integer userId){
        return usersService.uploadAvatar(mpFile, userId);
    }

    // 获取用户信息
//    @GetMapping("/getUserData")
//    @Operation(summary = "请求获取用户信息")
//    public Result<UserVO> getUser(@RequestHeader("Authorization") String authorization, @RequestParam(value = "openid", required = false, defaultValue = "")String openid) {
//        if (openid.equals("")) {
//            openid = authorization;
//        }
//        return Result.success(userServiceImpl.getUser(openid));
//    }

    @GetMapping("/getUserData")
    @Operation(summary = "请求获取用户信息")
    public Result<UserVO> getUser() {
      return   usersService.getUser();
    }

    // 修改用户信息
    @PostMapping("/updateUserData")
    @Operation(summary = "修改用户信息")
    public Result updateUserData(@RequestBody Users users) {
        return usersService.updateUserData(users);
    }

    //关注用户
    @PostMapping("/focus")
    @Operation(summary = "关注用户")
    public Result focus(@RequestBody FocusBehaviorDto  dto) {
       return usersService.focus(dto);
    }

    @Operation(summary = "获取用户列表")
    @GetMapping("/getUserList")
    public Result<List<Users>> getUserList() {
        return usersService.getUserList();
    }

}
